home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / wxlslib.zip / xlslib / examples / bcdemo.lsp < prev    next >
Lisp/Scheme  |  1992-02-20  |  2KB  |  52 lines

  1. ;; define a function to compute the Box-Cox transformation
  2. (defun bc (x c p)
  3.   (let* ((x (- x c))
  4.          (bcx (if (< (abs p) .0001)
  5.                   (log x)
  6.                   (/ (^ x p) p)))
  7.          (min (min bcx))
  8.          (max (max bcx)))
  9.     (/ (- bcx min) (- max min))))
  10.  
  11.  
  12. ;; get a sorted sample from a shi-squared distribution
  13. (def x (sort-data (chisq-rand 30 4)))
  14.  
  15. ;; compute the normal quantiles of the expected uniform order statistics
  16. (def r (normal-quant (/ (iseq 1 30) 31)))
  17.  
  18. ;; construct an initial plot without transformation
  19. (def myplot (plot-points r (bc x 0 1)))
  20.  
  21. ;;;
  22. ;;; First approach: compute as needed
  23. ;;;
  24. ;; construct a dialog for scrolling through powers and recomputing the
  25. ;; plot
  26. #|
  27. (interval-slider-dialog (list -1 2)
  28.                         :points 20
  29.                         :action #'(lambda (p)
  30.                                    (send myplot :clear nil)
  31.                                    (send myplot 
  32.                                          :add-points r (bc x 0 p))))
  33. |#
  34. ;;;
  35. ;;; Second aproach: precompute
  36. ;;;
  37. ;; construct a list of powers
  38. (def powers (rseq -1 2 16))
  39.  
  40. ;; compute transformed data for each power
  41. (def xlist (mapcar #'(lambda (p) (bc x 0 p)) powers))
  42.  
  43. ;; construct a dialog for scrolling through the list of data sets
  44. ;; and redrawing the plot
  45. (sequence-slider-dialog xlist
  46.                              :display powers
  47.                              :action #'(lambda (x)
  48.                                          (send myplot :clear nil)
  49.                                          (send myplot :add-points r x)))
  50.  
  51.       
  52.